package com.fy.utilsproject.fragments;

import android.animation.Animator;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fy.utilsproject.R;
import com.fy.utilsproject.anim.AnimationUtil;

public class AnimTestFragment extends Fragment implements View.OnClickListener {

    public static final String TAG = "AnimTestFragment";

    private TextView tv_fragment_anim_test_text;

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;


    public AnimTestFragment() {
    }

    public static AnimTestFragment newInstance(String param1, String param2) {
        AnimTestFragment fragment = new AnimTestFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_anim_test, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        View rootView = getView();
        if (rootView != null) {
            tv_fragment_anim_test_text = rootView.findViewById(R.id.tv_fragment_anim_test_text);
            rootView.findViewById(R.id.btn_fragment_anim_test_start).setOnClickListener(this);
        }
    }


    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_fragment_anim_test_start:
                AnimationUtil.translationVerticalByValueAnimator(tv_fragment_anim_test_text, 2000, 0, 100, new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        Log.d(TAG,"--onAnimationStart--");
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        Log.d(TAG,"--onAnimationEnd--");
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        Log.d(TAG,"--onAnimationCancel--");
                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {
                        Log.d(TAG,"--onAnimationRepeat--");
                    }
                });
                break;
        }
    }
}
